<!--
* writer: 姜
* create date: 2018年6月15日
* rewriter:
* rewrite date:
* description:附近农场
· -->

<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <style>
        body {
            background: #000;
        }
    </style>
</head>

<body>
    <div id="app">

    </div>
</body>

</html>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    var vm = new Vue({
        el: '#app',
        data: {
            token: ''
        },
        methods: {
            //刷新未读消息
            init: function(url) {
                vm.videoPlay(url);
                alert(url)
            },
            // 视频播放
            videoPlay: function(url) {
                console.log(url+'1111')
                var playModule = api.require('playModule');
                api.setFullScreen({
                    fullScreen: true
                });
                api.ajax({
                    url: url,
                    method: 'get',
                }, function(ret, err) {
                    //alert(JSON.stringify(ret))
                  //alert(JSON.stringify(err))
                    if (ret) {
                        var videoResolution = 0;
                        if (ret.streams[0].side_data_list) {
                            videoResolution = Math.abs(ret.streams[0].side_data_list[0].rotation)
                        } else if (ret.streams[1].side_data_list) {
                            videoResolution = Math.abs(ret.streams[1].side_data_list[0].rotation)
                        } else {
                            videoResolution = 0
                        }

                        console.log(videoResolution)
                        if (videoResolution == 0 || videoResolution == 180) {
                            playModule.play({
                                rect: {
                                    x: 0,
                                    y: 0,
                                    w: api.winWidth,
                                    h: api.winHeight
                                },
                                fixedOn: api.frameName,
                                url: url,
                                scalingMode: 1,
                                enableFull: false,
                                fullscreenMode: 'LANDSCAPE',
                                isLocalCache: true,
                                enableFullAutoClose: true,
                                isAutoPlay: true,
                                isLoop: false,
                                isBackBtn: true
                            }, function(ret, err) {
                                var edit = "setVideoStatus();";
                                api.execScript({
                                    name: 'root',
                                    script: edit
                                });
                            });
                        } else if (videoResolution == 90 || videoResolution == 270) {
                            playModule.play({
                                rect: {
                                    x: 0,
                                    y: 0,
                                    w: api.winWidth,
                                    h: api.winHeight
                                },
                                fixedOn: api.frameName,
                                url: url,
                                scalingMode: 1,
                                enableFull: false,
                                fullscreenMode: 'PORTRAIT',
                                isLocalCache: true,
                                enableFullAutoClose: true,
                                isAutoPlay: true,
                                isLoop: false,
                                isBackBtn: true
                            }, function(ret, err) {
                                var edit = "setVideoStatus();";
                                api.execScript({
                                    name: 'root',
                                    script: edit
                                });
                            });
                        }
                    } else {
                        toast_global('视频加载失败，请重试！');
                        setTimeout(function() {
                            api.closeWin();
                            api.setFullScreen({
                                fullScreen: false
                            });
                            var header = document.querySelector('#header');
                            if (header) {
                                $api.fixStatusBar(header);
                            }

                            var footer = document.querySelector('#footer');
                            if (footer) {
                                $api.fixTabBar(footer)
                            }
                        }, 300)
                    }
                });

                playModule.addEventListener({
                    name: 'backBtn'
                }, function(ret, err) {
                    closeWin();
                    api.setFullScreen({
                        fullScreen: false
                    });
                });
            }
        }
    });

   apiready = function() {

        // 苹果端屏蔽返回事件
        if (api.systemType == 'ios') {
            api.addEventListener({
                name: 'swiperight'
            }, function(ret, err) {
                api.setScreenOrientation({
                    orientation: 'portrait_up'
                });
                return false
            });
        }

        api.parseTapmode()

        vm.init(api.pageParam.files);


        // if (api.systemType == 'ios') {
        //     api.addEventListener({
        //         name: 'swiperight'
        //     }, function(ret, err) {
        //       // 关闭全屏视频
        //       closeWin();
        //       var playModule = api.require('playModule');
        //       playModule.unfull(function(ret, err) {});
        //         return false
        //     });
        // }

    }
</script>
